<template>
  <div id="wrapper">
    <shop-head></shop-head>
    <router-view v-if="isRouterAlive"></router-view>
  </div>
</template>

<script>
import ShopHead from "./components/ShopHead.vue";
export default {
  name: "App",
  components: {
    ShopHead,
  },
  provide() {
    //父组件中通过provide来提供变量，在子组件中通过inject来注入变量。
    return {
      reload: this.reload,
    };
  },
  data() {
    return {
      isRouterAlive: true, //控制视图是否显示的变量
    };
  },
  methods: {
    userinfo() {
      var user = sessionStorage.getItem("user");
      this.$store.state.user = JSON.parse(user);
    },
    reload() {
      this.isRouterAlive = false; //先关闭，
      this.$nextTick(function () {
        this.isRouterAlive = true; //再打开
      });
    },
  },
  created() {
    this.userinfo();
    
  },
  watch: {
    $route: "userinfo",
  },
};
</script>

<style scoped>
div {
  text-align: left;
}
</style>
